From: Matthieu Gallien Date: Thu, 6 Feb 2025 10:34:49 +0000 (+0100) Subject: remove duplicated code in ClientSideEncryption class X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~2^2~87^2~1 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=a4dfef2daf5c32d1d70295777d4524d9c7a2d662;p=nextcloud-desktop.git remove duplicated code in ClientSideEncryption class Signed-off-by: Matthieu Gallien --- diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp index a80268dad..c65c6639a 100644 --- a/src/libsync/clientsideencryption.cpp +++ b/src/libsync/clientsideencryption.cpp @@ -1316,38 +1316,6 @@ void ClientSideEncryption::fetchPublicKeyFromKeyChain(const AccountPtr &account) job->start(); } -bool ClientSideEncryption::checkPublicKeyValidity(const AccountPtr &account) const -{ - QByteArray data = EncryptionHelper::generateRandom(64); - - Bio publicKeyBio; - QByteArray publicKeyPem = account->e2e()->getPublicKey().toPem(); - BIO_write(publicKeyBio, publicKeyPem.constData(), publicKeyPem.size()); - auto publicKey = PKey::readPublicKey(publicKeyBio); - - auto encryptedData = EncryptionHelper::encryptStringAsymmetric(account->e2e()->getCertificateInformation(), account->e2e()->paddingMode(), *account->e2e(), data); - if (!encryptedData) { - qCWarning(lcCse()) << "encryption error"; - return false; - } - - auto key = _encryptionCertificate.getEvpPrivateKey(); - - const auto decryptionResult = EncryptionHelper::decryptStringAsymmetric(account->e2e()->getCertificateInformation(), account->e2e()->paddingMode(), *account->e2e(), *encryptedData); - if (!decryptionResult) { - qCWarning(lcCse()) << "encryption error"; - return false; - } - const auto decryptResult = QByteArray::fromBase64(*decryptionResult); - - if (data != decryptResult) { - qCInfo(lcCse()) << "invalid private key"; - return false; - } - - return true; -} - bool ClientSideEncryption::checkEncryptionIsWorking() const { qCInfo(lcCse) << "check encryption is working before enabling end-to-end encryption feature"; @@ -2296,7 +2264,7 @@ void ClientSideEncryption::decryptPrivateKey(const AccountPtr &account, const QB } } - if (!getPrivateKey().isNull() && checkPublicKeyValidity(account)) { + if (!getPrivateKey().isNull() && checkEncryptionIsWorking()) { writePrivateKey(account); writeCertificate(account); writeMnemonic(account, [] () {}); diff --git a/src/libsync/clientsideencryption.h b/src/libsync/clientsideencryption.h index 75bb149c9..fd7f369af 100644 --- a/src/libsync/clientsideencryption.h +++ b/src/libsync/clientsideencryption.h @@ -395,7 +395,6 @@ private: SUCCESS_CALLBACK nextCheck, ERROR_CALLBACK onError); - [[nodiscard]] bool checkPublicKeyValidity(const AccountPtr &account) const; [[nodiscard]] bool checkServerPublicKeyValidity(const QByteArray &serverPublicKeyString) const; [[nodiscard]] bool sensitiveDataRemaining() const;